import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Index',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/Home/Index.vue')
  },
  {
    path: '/home2',
    name: 'Home2',
    component: () => import('../views/Home/Home.vue')
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})



router.beforeEach((to, from, next) => {
  const isLogin = localStorage.getItem('isLogin');
  const unPermission = ['Login']

  if (!unPermission.includes(to.name) && !isLogin) {
    alert('请登陆后使用');
    next({ name: 'Login' });
  } else {
    next();
  }
})

export default router
